package com.mall.xiaomi.service.impl;

import com.mall.xiaomi.exception.ExceptionEnum;
import com.mall.xiaomi.exception.XmException;
import com.mall.xiaomi.mapper.ProductPictureMapper;
import com.mall.xiaomi.pojo.ProductPicture;
import com.mall.xiaomi.service.ProductPictrueService;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

/**
 * @author XueWanglin
 * @ClassName ProductPictureServiceImpl
 * @Description TODO
 * @Date 2021/2/26 11:02
 * @Version 1.0
 */
@Service
public class ProductPictureServiceImpl implements ProductPictrueService {

    @Autowired(required = false)
    private ProductPictureMapper productPictureMapper;

    @Override
    public List<ProductPicture> selectPicturesByProductId(Integer productId) {
        ProductPicture productPicture = new ProductPicture();
        productPicture.setProductId(productId);
        List<ProductPicture> list = null;
        try {
            list = productPictureMapper.select(productPicture);
            if (ArrayUtils.isEmpty(list.toArray())){
                throw new XmException(ExceptionEnum.GET_PRODUCT_PICTURE_NOT_FOUND);
            }
        }catch (Exception e){
            e.printStackTrace();
            throw new XmException(ExceptionEnum.GET_PRODUCT_PICTURE_ERROR);
        }
        return list;
    }
}
